<template>
  <div class="app-container log">
    <el-form :model="queryParam" ref="queryForm" :inline="true"  style="text-align: center; height: 88px;">
      <el-row style="margin: auto; width: 100%; text-align: center; height: 37px;">
        <h1 style="display: inline-block; margin-top: -4px; text-align: center; color: #8b836c; font-size: 1.5rem; letter-spacing: 1px; font-family: serif;">系统日志列表</h1>
      </el-row>
      <el-row style="height: 40px">
        <el-form-item label="员工：">
          <el-select v-model="queryParam.userId" filterable placeholder="请选择（或输入）员工姓名" clearable>
            <el-option
              v-for="item in relaEmpList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
              :title="item.name">
              <span>{{ item.name }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button style="margin-left: 16px" size="medium" class="qryBtn" @click="submitForm">查询</el-button>
        </el-form-item>
      </el-row>
    </el-form>

    <el-table
      v-loading="listLoading"
      :data="tableData"
      fit 
      highlight-current-row
      style="
        width: 99.2%;
        border: 1px solid rgb(220, 223, 230);
        margin-bottom: 12px;
        border-radius: 10px;
        over-flow: auto;
      "
      max-height="500px"
      :header-cell-style="{
        'color':'#ffffff',
        'border-bottom-radius': '1px',
        'font-size':'0.86rem',
        'height':'8px',
        'font-family': 'serif',
        'font-weight': '800',
        'background': '#a2997f',
        'border-right-color': '#b6b6b1',
        'border-bottom-color': '#b6b6b1',
        'border-width': '1.2px'
      }"
      border>
      <el-table-column prop="id" label="编号" width="90" />
      <el-table-column prop="realName" label="员工" width="100" />
      <el-table-column prop="content" label="动态" />
      <el-table-column prop="createTime" label="创建时间" width="190px"/>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParam.pageIndex" :limit.sync="queryParam.pageSize"
                @pagination="search"/>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import userApi from '@/api/user'

export default {
  components: { Pagination },
  data () {
    return {
      relaEmpList: [],
      queryParam: {
        userId: null,
        userName: null,
        pageIndex: 1,
        pageSize: 10
      },
      listLoading: true,
      tableData: [],
      total: 0
    }
  },
  created () {
    let userId = this.$route.query.userId
    if (userId && parseInt(userId) !== 0) {
      this.queryParam.userId = userId
    }

    userApi.userFilter().then(res => {
      this.relaEmpList = res.response
    })
    this.search()
  },
  methods: {
    search () {
      this.listLoading = true
      userApi.getUserEventPageList(this.queryParam).then(data => {
        const re = data.response
        this.tableData = re.list
        this.total = re.total
        this.queryParam.pageIndex = re.pageNum
        this.listLoading = false
      })
    },
    submitForm () {
      this.queryParam.pageIndex = 1
      this.search()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang='scss'>
.log .el-row {
  position: relative;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  height: 50px;
}
</style>